<template>
	<view class="item-block">
		<view class="bot-item">
			<view class="item-list">
				<view class="list_item">
					<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltolower="lower"
						:style="{ height: `calc(100vh - 30px)` }">
						<view class="polular_list_item" v-for="(item,index) in datalist" :key="index">

							<view class="item_left">
								<view class="title_item item_hed">
									<u-avatar :src="item.avatarUrl" size="30"></u-avatar>
									<span>{{item.nickName}}</span>
								</view>
								<view class="team_item">
									申请时间：{{item.insertTime}}
								</view>
								<view class="team_item">
									申请原因：{{item.messageType==2?'申请退出退伍':'申请解散队伍'}}
								</view>
								<view class="team_item" v-if="item.checkReason"  style="color: #de3600;">
									拒绝原因：{{item.checkReason}}
								</view>

							</view>
							<view class="item_right" v-if='item.enableCheck==1 && item.checkState==0'>
								<u-button type="primary" class="yesbut" text="同意" @click="agree(item.id)"></u-button>
								<u-button type="error" text="拒绝" @click="refuse(item.id)"></u-button>
							</view>
							<view class="iconitem">
								<view class="iconfont icon-shenhezhong" v-if="item.checkState==0">

								</view>
								<view class="iconfont icon-yitongguo" v-else-if="item.checkState==1">

								</view>
								<view class="iconfont icon-yijujue" v-else-if="item.checkState==2">

								</view>
							</view>
						</view>
						<u-loadmore line :status="status" :loading-text="loadingText" :nomore-text="nomoreText"
							v-if="this.pagetotal!=0" />
					</scroll-view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				teamId: '',
				datalist: [],
				query: {
					pagNum: 1,
					pageSize: 10,

				},
				status: 'loading',
				loadingText: '努力加载中',
				nomoreText: '没有更多了',
				pagetotal: 0,
			}
		},
		created() {

		},
		onLoad(options) {
			// 从路由参数中获取传递的值			
			const id = decodeURIComponent(options.id);
			this.teamId = id
		},
		mounted() {
			this.eventlist()
			const eventChannel = this.getOpenerEventChannel()
			eventChannel.emit('reverseData', {
				data: true
			})

		},
		methods: {
			agree(e) {
				const that = this
				this.$request(`/message/checkSuccess/${e}`, 'get')
					.then(
						res => {
							console.log(res);
							if (res.data.data) {
								const eventChannel = that.getOpenerEventChannel()
								eventChannel.emit('reverseData', {
									data: true
								})
								that.$refs.uToast.show({
									type: 'success',
									message: "提交成功",
									iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',

								})
								that.datalist = []
								that.query.pagNum = 1
								that.eventlist()
							} else {
								that.$refs.uToast.show({
									type: 'error',
									message: "提交失败",
									iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/top.png',

								})
							}
						})
			},
			refuse(e) {
				const that = this
				this.$request(`/message/checkFail/${e}`, 'get')
					.then(
						res => {
							if (res.data.data) {
								that.$refs.uToast.show({
									type: 'success',
									message: "提交成功",
									iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',

								})
								that.datalist = []
								that.query.pagNum = 1
								that.eventlist()
							} else {
								that.$refs.uToast.show({
									type: 'error',
									message: "提交失败",
									iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/top.png',

								})
							}
						})
			},
			// 消息列表数据
			eventlist() {
				const that = this
				this.$request(`/message/listByPage/${this.teamId}/${this.query.pagNum}/${this.query.pageSize}`, 'get')
					.then(
						res => {
							const array = res.data.data.records
							this.datalist = this.datalist.concat(array)
							this.pagetotal = res.data.data.total
							if (this.pagetotal == this.datalist.length || res.data.data.total == 0) {
								this.status = 'nomore'
							}
						})
			},

			// 分页
			lower() {
				this.status = 'loading'

				setTimeout(() => {
					this.query.pagNum++
					this.eventlist()
				}, 2000);
			},


		}
	}
</script>

<style scoped lang="scss">
	.item-block {
		height: 100vh;

		::-webkit-scrollbar {
			width: 0px;
			/* 滚动条的宽度 */
		}

		.header-search {
			padding: 10px 20px;

			::v-deep .u-input {
				background-color: #f6f7f9;
				// border: 1px solid #dededf;
				border-radius: 18px;
				box-shadow: 0 0 2px #b9b9ba;

				/* 添加阴影 */
				.u-icon__icon {
					color: #de3600 !important;
					font-size: 25px !important;
					font-weight: 700 !important;

				}
			}
		}

		.bot-item {
			height: calc(100vh - 20px);
			background-color: #f4f4f4;
			border-radius: 15px 15px 0 0;
			padding: 10px 20px;

			::v-deep .u-input {
				border-bottom: 1px solid #d1d1d1;

			}

			.item-list {
				margin-top: 10px;

				.polular_list_item {
					background-size: 100% auto;
					margin-bottom: 10px;
					min-height: 70px;
					background-color: #fff;
					border-radius: 10px;
					box-shadow: 0 0 2px #b9b9ba;
					padding: 8px 15px;
					display: flex;
					justify-content: space-between;
					position: relative;

					.iconitem {
						position: absolute;
						top: 0;
						right: 0;

						.icon-shenhezhong,
						.icon-yitongguo,
						.icon-yijujue {
							font-size: 40px;
						}

						.icon-shenhezhong {
							color: #ffaa00;
						}

						.icon-yitongguo {
							color: #00aa00;
						}

						.icon-yijujue {
							color: #aa0000;
						}
					}

					.item_left {
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.item_hed {
							display: flex;
							align-items: center;

							span {
								margin-left: 10px;
							}

						}

						.title_item {
							font-size: 32rpx;
							font-weight: 600;
						}

						.team_item {
							margin: 3px 0;
							font-size: 12px;
							color: #afafaf;
						}

						.address_item {
							margin-top: 20px;

							.icon-dizhi {
								font-size: 13px;
								border-radius: 10px;
								padding: 2px;
								background-color: #de3600;
								color: #fff;
								margin-right: 3px;
							}

							.address_text {
								font-size: 12px;
								color: #afafaf;
							}
						}
					}

					.item_right {
						display: flex;
						align-items: flex-end;

						::v-deep .u-button:first-child {
							color: #f6f7f9;
							border: 0px;
							border-radius: 30px;
							background-color: #00aaff;
							height: 30px;
							width: 55px;
							margin-right: 10px;
						}

						::v-deep .u-button:last-child {
							color: #f6f7f9;
							border: 0px;
							border-radius: 30px;
							background-color: #de3600;
							height: 30px;
							width: 55px;
						}

					}
				}

			}
		}
	}
</style>